import { resolve } from 'node:path';
import vue from '@vitejs/plugin-vue'
import UnoCSS from 'unocss/vite'
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers';
import Components from 'unplugin-vue-components/vite';
import { defineConfig, loadEnv } from 'vite'
import viteDevtools from 'vite-plugin-vue-devtools';

// https://vitejs.dev/config/
export default ({ mode }: any) => {
	const env = loadEnv(mode, process.cwd())
	return defineConfig({
		build: {
			chunkSizeWarningLimit: 1024,
			rollupOptions: {
				output: {
					// manualChunks: {
					// 	antd: ['ant-design-vue'],
					// },
					manualChunks(id) {
						if (id.includes('ant-design-vue')) {
							return 'antd';
						}
						if (id.includes('service-add')) {
							return 'service-add';
						}
					}
				},
			},
		},
		server: {
			host: '0.0.0.0',
			port: 5173,
			proxy: {
				'/api': {
					// target: 'http://139.155.137.11:80',
					target: 'https://guangheky.com',
					changeOrigin: true,
				},
			},
			// warmup: {
			// 	clientFiles: [
			// 		'./src/views/care.vue',
			// 		'./src/assets/bg.svg',
			// 	],
			// },
		},
		base: env.VITE_BASE_URL,
		resolve: {
			alias: {
				'@': resolve(__dirname, './src'),
			},
		},
		plugins: [
			Components({
				resolvers: [
					AntDesignVueResolver({
						importStyle: false, // css in js
					}),
				],
			}),
			viteDevtools(),
			UnoCSS(),
			vue(),
		],
	})
}
